package cfs.formbean;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author danny seow
 */
//import org.mybeans.form.FileProperty;
//import org.mybeans.form.FormBean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class FundForm extends FormBean {
	private String name;
	private String symbol;

	public String getName() {
		return name;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setName(String name) {
		this.name = name.trim();
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol.trim();
	}

	@Override
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (name == null || name.length() == 0) {
			errors.add("Name of Fund is required");
		}

		if (symbol == null || symbol.length() == 0) {
			errors.add("Fund Symbol is required");
		}

		if (errors.size() > 0)
			return errors;

		if (symbol.matches(".*[<>\"].*")) {
			errors.add("Do not try to inject html codes to Symbol Text Field");
			symbol = this.trimAndConvert(symbol, "<>\"");
		}
		if (name.matches(".*[<>\"].*")) {
			errors.add("Do not try to inject html codes to Name Text Field");
			name = this.trimAndConvert(name, "<>\"");
		}

		if (symbol.length() < 4 || symbol.length() > 4) {
			errors.add("Fund Symbol must only be 4 Letters");
		}

		return errors;
	}

}
